function ctrlInitArrowTableTreeColumn(context, selector, data){
	var table = $(selector, context).parents("table").eq(0);
	//data.tableId
	var cookieName = 'ctrl-table-tree' + data.tableId;
	var expanded = ($.cookie(cookieName)+"").split(";");
	
	$(".ctrl-table-cell-tree", table).each(function(){
		var path = $(this).attr("path");
		var depth = $(this).attr("depth");
		
		$(this).parents("tr").eq(0).attr("path", path).attr("depth", depth);
	})
	
	$(".ctrl-table-cell-tree img", table).draggable({ 
		revert: false, 
		helper: function(ev){
			var el = $("<div>" + $(ev.target).parent().html() +"</div>");
			$(".ctrl-table-field-tree-opened, .ctrl-table-field-tree-closed", el).remove();
			return $('<div style="background-color:white; border: solid 1px rgb(175, 180, 155); padding: 3px; width: 200px; cursor:n-resize;" ></div>').append(el); 
		},
		start: function(){ $("#struct-target").toggleClass("list"); $("#root-node").toggle(); },
		stop: function(){ $("#struct-target").toggleClass("list"); $("#root-node").toggle(); }
	}).each(function(){
		$(this).attr("alt", $(this).parent().find(".id").text());
	});
	
	$(".ctrl-table-move", table).click(function(){
		var href = $(this).attr("href");
		$.get(href, function(){
			CtrlAjax.changeStateVars(table, {}, {});
			
		});
		return false;
	});
	
	
	
	$(".ctrl-table-cell-tree").droppable({
		hoverClass: 'ctrl-table-drop-to-structure',
		drop: function(event, ui){
			
			if( ui.draggable ){
				var test = true;
				if (confirm("Czy na pewno chcesz przenieść węzeł \n\n \"" +  ui.draggable.parent().find("span:eq(0)").text() + "\" \n\n do \n\n \"" + $(this).find("span").text()+ "\n" )){		
					var sourceId = ui.draggable.attr("alt");
					var targetId = $(".id",this).text();
					
					ArrowDataConnector.saveObjectData( data.model, sourceId, {
							parent_id: targetId
						},{ 
							disable: table,
							errorCallback: function(){
								alert("Nie można wykonać takiej operacji!");
								Page.reloadHandler(true);
							} 
						},
						function( response ){
							CtrlAjax.changeStateVars(table, {}, {});
						}
					);
				}	
			}
			return false;
		}
	});	
	
	
	$(".ctrl-table-field-tree-opened", table).click(function(){
		var path = $(this).attr("href");
		var depth = parseInt($(this).attr("rel"));
		
		var childrenCount = $("tr[path^='"+path+"_']", table).length;
		if(childrenCount == 0){
			$(this).remove();
		}
			
		if( $(this).hasClass("ctrl-table-field-tree-opened") ){
			$("tr[path^='"+path+"_']", table).css({display: 'none'});
			$(this).removeClass('ctrl-table-field-tree-opened').addClass('ctrl-table-field-tree-closed');
			for(var i=0;i<expanded.length;i++)
				if(path == expanded[i])
					delete expanded[i];	
		}else{
			$("tr[path^='"+path+"_'][depth='"+ (depth+1) +"']", table).css({display: ''});
			$(this).removeClass('ctrl-table-field-tree-closed').addClass('ctrl-table-field-tree-opened');
			expanded.push(path);
		}
		$.cookie(cookieName, expanded.join(";"));
		return false;
	}).each(function(){
		var path = $(this).attr("href");
		var finded = false; 
		for(var i=0;i<expanded.length;i++){		
			if(path == expanded[i])
				finded = true;
		}
		if(!finded) $(this).click();
	});
	
}